package org.vsc.security;

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;

import org.apache.commons.codec.binary.Base64;

public class KeyGenerator {
	public static void main(String[] args) throws Exception{
		KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
        SecureRandom sr = new SecureRandom();
        sr.setSeed(System.currentTimeMillis());
        keygen.initialize(1024, sr);
        KeyPair keyPair = keygen.generateKeyPair();
        System.out.println(new String(Base64.encodeBase64(keyPair.getPrivate()
                .getEncoded(), true)));
        System.out.println(new String(Base64.encodeBase64(keyPair.getPublic()
                .getEncoded(), true)));
        String test = "yeqin\\ghen//\bgtestyeqinghe\\ngt\\estyeqinghengtestyeqinghengtestyeqinghengtestyeqinghengtestyeqinghengtestyeqinghengtestyeqinghengtestyeqinghengtestyeqinghengtest";
        String enTest = RSAEncrypt.encrypt(test, "");
        String deTest = RSAEncrypt.decrypt(enTest, "");
        System.out.println(test);
        System.out.println(enTest);
        System.out.println(deTest);
	}
}
